蟻本 2-2 Fence Repair
code: python
import heapq
n = int(input())
l = list(map(int, input().split()))
ans = 0
# 優先度付きキューに変換
heapq.heapify(l)
while len(l) > 1:
# 一番短い板と二番目に短い板
x = heapq.heappop(l) + heapq.heappop(l)
ans += x
heapq.heappush(l, x)
print(ans)